In computing, an escape sequence is a sequence of characters that has a special semantic meaning based on an established convention that specifies an escape character prefix in addition to the syntax of the rest of the Text string of a sequence. A convention can define any particular character code as a sequence prefix. Some conventions use a normal, printable character such as backslash (\) or ampersand (&). Others use a non-printable (a.k.a. control) character such as ASCII escape.
Escape sequences date back at least to the 1874 Baudot code.
In C and many derivative programming languages, a backslash (\) in a string literal marks the beginning of an escape sequence. Common escape sequences include: carriage return , newline , tab character . To account for the fact that using a printable character for escape causes that character to lose its normal meaning, a sequence of two backslash characters (\) encodes a single backslash. An escape sequence can also specify a character by its code value. For example, the backslash can be encoded as either \\ or \x5c which specify the character code value as hexadecimal and octal, respectively.
A backslash immediately followed by a newline (which is necessarily outside of a string literal) does not mark an escape sequence. The C preprocessor joins the line with the subsequent line.
In C and many related languages, the escape character is the backslash (). The single quotation mark character can be coded as <nowiki></nowiki> since ^ is not valid. As a string literal is delimiter by double-quotes (<nowiki></nowiki>) the content cannot contain a double-quote unless it is escaped (<nowiki></nowiki>) or via a sequence that specifies the code of the double-quote character (").
In Perl or Python 2, the following is invalid syntax:
This can be fixed by inserted backslash to escape:
Alternatively, the following uses "\x" to indicate the subsequent two characters are hexadecimal digits; "22" being the hexadecimal ASCII value for double-quote.
C, C++, Java, and Ruby allow the same two backslash escape styles. PostScript and rich text format (RTF) also use backslash escapes. The quoted-printable encoding uses the equals sign as an escape character. URL and URI use percent-encoding to quote characters with a special meaning, as for non-ASCII characters.
The later VT100 terminal implemented the more sophisticated ANSI escape sequences standard (now ECMA-48) for functions such as controlling cursor movement, character set, and display enhancements. The HP 2640 series had perhaps the most elaborate escape sequences for block and character modes, programming keys and their soft labels, graphics vectors, and even saving data to tape or disk files.
In Windows (and MS-DOS), a utility, ANSI.SYS, can be used to enable ANSI escape sequence support. In DOS via "\"" in the PROMPT command), and in 16-bit Windows via a command window. In Unix and Unix-like systems, the ANSI escape sequences are generally supported by the shell. The rise of GUI applications has reduced the use of escape sequences, yet the ability to provide full-screen, text-based applications is still available.
Escape sequences in communications are commonly used when a computer and a peripheral have only a single channel through which to send information back and forth (so escape sequences are an example of in-band signaling). They were common when most dumb terminals used ASCII with 7 data bits for communication, and sometimes would be used to switch to a different character set for "foreign" or graphics characters that would otherwise been restricted by the 128 codes available in 7 data bits. Even relatively "dumb" terminals responded to some escape sequences, including the original mechanical Teletype printers (on which "glass Teletypes" or VDUs were based) responded to characters 27 and 31 to alternate between letters and figures modes.
|
|